﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Globalization;
using CMCCMicroBlog.ViewModels;

namespace CMCCMicroBlog
{
    public class FeedConverter:IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            FeedModel feed = (FeedModel)value;
            string param=parameter.ToString();

            if (param.Equals("visibility"))
            {
                return (feed.RootFeed==null)?Visibility.Collapsed:Visibility.Visible;
            }
            else if (param.Equals("icon"))
            {
                return feed.Icon;
            }
            else if (param.Equals("nickname"))
            {
                return feed.NickName;
            }
            else if (param.Equals("text"))
            {
                return feed.Text;
            }
            else if (param.Equals("roottext"))
            {
                return (feed.RootFeed == null) ? "" : feed.RootFeed.Text;
            }
            else if (param.Equals("margin"))
            {
                return (feed.RootFeed == null) ? "8,2,0,2" : "20,2,0,2";
            }
            else if (param.Equals("picvisibility"))
            {
                if (feed.RootFeed == null)
                {
                    return (feed.ThumbnailPic == null) ? Visibility.Collapsed : Visibility.Visible;
                }
                else
                {
                    return (feed.RootFeed.ThumbnailPic == null) ? Visibility.Collapsed : Visibility.Visible;
                }
            }
            else if (param.Equals("thumbnailpic"))
            {
                if (feed.RootFeed == null)
                {
                    return (feed.ThumbnailPic == null) ? "" : feed.ThumbnailPic;
                }
                else
                {
                    return (feed.RootFeed.ThumbnailPic == null) ? "" : feed.RootFeed.ThumbnailPic;
                }
            }
            else if (param.Equals("originalpic"))
            {
                if (feed.RootFeed == null)
                {
                    return (feed.OriginalPic == null) ? "" : feed.OriginalPic;
                }
                else
                {
                    return (feed.RootFeed.OriginalPic == null) ? "" : feed.RootFeed.OriginalPic;
                }
            }
            return Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value.Equals(Visibility.Visible))
            {
                return true;
            }
            return false;
        }
    }
}
